package com.hwl.lab.controller;

import com.hwl.lab.entity.Area;
import com.hwl.lab.entity.Zheng;
import com.hwl.lab.repository.ZhengRepository;
import com.hwl.lab.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin //允许跨域请求
@RestController
public class ZhengController {
    @Autowired
    ZhengRepository zhengRepository;
    //查询所有（分页）
    @GetMapping("/findZhengAll/{page}/{size}")
    public Page<Zheng> findAreaAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return zhengRepository.findAll(pageable);
    }
    //添加，修改
    @PostMapping("/saveZheng")
    public void saveFamily(@RequestBody(required=false) Zheng zheng){
        zhengRepository.save(zheng);
    }
    //删除
    @PostMapping("/deleteZheng/{id}")
    public void deleteArea(@PathVariable("id") Long id){
        zhengRepository.deleteById(id);
    }
}
